﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.SettingManagement;
using Volo.Abp.Settings;

namespace Himp.Platform
{
    /// <summary>
    /// 
    /// </summary>
    public class SysSettingService : PlatformAppService
    {
        private readonly ISettingManager _settingManager;

        public SysSettingService(ISettingManager settingManager)
        {
            _settingManager = settingManager;
        }

        /// <summary>
        /// ocean 2024-4-25
        /// 获取系统设置参数
        /// </summary>
        /// <returns></returns>
        public virtual async Task<SysSettingDto> GetAsync(string key)
        {
            var systemSettingsDto = new SysSettingDto
            {
                ConfigKey = key,
                ConfigValue = await _settingManager.GetOrNullGlobalAsync(key),
            };

            return systemSettingsDto;
        }

        /// <summary>
        /// ocean 2023-9-4
        /// 更新系统设置参数
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public virtual async Task PutAsync(SysSettingDto input)
        {
            await _settingManager.SetGlobalAsync(input.ConfigKey, input.ConfigValue);
        }
    }
}
